package com.example.usingintent;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {

	int reqCode = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	public void onClick(View view) {
		// TODO Auto-generated method stub
		// startActivity(new Intent("com.example.usingintent.SecondActivity"));
		// startActivity(new Intent(this, SecondActivity.class));
		// startActivityForResult(new
		// Intent("com.example.usingintent.SecondActivity"), reqCode);

		Intent i = new Intent("com.example.usingintent.SecondActivity");
		// ---use putExtra() to add new name/value pairs---
		i.putExtra("str1", "This is a string");
		i.putExtra("age1", 25);
		// ---use a Bundle object to add new name/values
		// pairs---
		Bundle extras = new Bundle();
		extras.putString("str2", "This is another string");
		extras.putInt("age2", 35);
		// ---attach the Bundle object to the Intent object---
		i.putExtras(extras);
		// ---start the activity to get a result back---
		startActivityForResult(i, 1);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == reqCode && resultCode == RESULT_OK) {
			Toast.makeText(this, Integer.toString(data.getIntExtra("age3", 1)), Toast.LENGTH_SHORT)
					.show();
			
			Toast.makeText(this, data.getData().toString(), Toast.LENGTH_SHORT).show();
		}
	}
}
